<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/8/26
 * Time: 9:36
 */

namespace app\validate;


use think\Validate;

class WebMember extends Validate
{
    protected $rule =   [
        'name|姓名'  => 'require|chs',
        'mobile|手机号'  => 'require|mobile|unique:web_member',
        'id_card|身份证号' => 'require|id_card|unique:web_member', //身份证号无需验证长度 直接idCard
        'password|密码'   => 'require|length:8,16|different:new_password',
        'new_password|新密码' => 'require|length:8,16|confirm',
        'new_password_confirm'  => 'require|length:8,16',
        'old_captcha' => 'require|number|length:6',
        'captcha' => 'require|number|length:6',
        'pay_password' => 'require|number|length:6|confirm',




//        ['phone', 'require|regex:^1[34578]{1}\d{9}$'],
    ];

    protected $message  =   [
        'mobile.require' => '手机号不能为空',
        'mobile.mobile'     => '请输入正确的手机号',
        'mobile.unique'   => '您的账号已在平台注册过',
        'id_card.idCard' => '请输入标准的身份证号',
        'password.length' => '密码请输入8-16位长度字符',
        'password.different' => '密码和新密码不能相同',
        'new_password.length' => '新密码请输入8-16位长度字符',
        'new_password.confirm' =>'新密码和确认密码不一致',


    ];

    // edit 验证场景定义
    public function sceneLogin()
    {
        //'mobile',
        return $this->only(['password'])
            ->remove('mobile','unique');
    }

    public function sceneRegister(){
        return $this->only(['mobile','id_card','password'])
            ->remove('id_card','id_card')
            ;

    }

    public function sceneUpdatePassword(){
        return $this
            ->only(['id_card','password','new_password','confirm_new_password'])
            ;
    }
    public function sceneForgetPassword(){
        return $this
            ->only(['id_card','new_password'])
            ->remove('mobile','unique')
            ->remove('id_card','unique|id_card')
            ->remove('new_password','confirm')
            ;
    }
//    protected $scene = [
//        'login'  =>  ['mobile' => 'require|tel','password' => 'require|length:6,12'],
//        'register' => ['username','password','password_comfirm','captcha'],
//        'web_register_data' => ['username','password' => 'require|length:6,12' ,'captcha' => 'require|number|length:6'],
//        'register_mini' => ['username' => 'require|tel','password','password_comfirm','captcha'],
//        'forget_password' => ['username' => 'require|tel','password' => 'require|length:6,12','captcha'],
//        'update_password' => ['old_password','password' => 'require|length:6,12|confirm'], //'username' => 'require|length:6,18',
//        'set_pay_password' => ['username' => 'require|tel','captcha','pay_password'],
//        'update_username' => ['username','old_captcha','captcha'],
//        'cert' => ['name','id_number','phone'],
//        'car' => ['name','driver','car_number','car_model']
//
//    ];
}